<?php
/**
 * Created by Engineer CuiLiwu.
 * Project: deal.
 * Date: 2018/6/14-17:47
 * License Hangzhou orce Technology Co., Ltd. Copyright © 2018
 */

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Events\ImEvent;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Routing\Router;
use Illuminate\Support\Arr;
use Illuminate\Routing\Route;
use Illuminate\Support\Str;
use App\Repository\Models\UserImNetcall;

class ImCrontabCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'crontab:imrecord';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'IM 自动查询并存储聊天记录';


    // protected $ordersCrontab_repo;

    /**
     * Execute the console command.
     * TODO 自动查询并存储聊天记录
     * @return mixed
     */
    public function handle()
    {
        //订单自动取消
        $this->imRecord();

    }
    public function imRecord(){
        try {
            // 查询已记录聊天会话
            $userImNetCall = UserImNetcall::query()->get()->toArray();
            if (count($userImNetCall)>0){
                foreach ($userImNetCall as $key=>$value){
                    $ImEvent = event(new ImEvent($value));
                    var_dump($ImEvent);
                }
            }
        }catch (\Exception $e) {
            var_dump(iconv('gbk', 'utf-8', $e->getMessage()));
            //var_dump($e->getMessage());
        }
    }

}